package com.hfi.util;

import org.springframework.util.StringUtils;

/**
 * @author ChangLiang
 * @date 2019/6/4
 */
public class IdUtil {

    private static final String SALT = "qwdfrgq12#213fefeff";
    private static final int LENGTH = 7;
    private static final String ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyz";

    public static String getMixId(String id){
        if (StringUtils.isEmpty(id)) {
            return "";
        }

        Hashids hashids = new Hashids(SALT, LENGTH, ALPHABET);
        String encode = hashids.encode(Long.valueOf(id));

        return encode;
    }

    public static String getId(String mixId){
        if (StringUtils.isEmpty(mixId)) {
            return "";
        }

        Hashids hashids = new Hashids(SALT, LENGTH, ALPHABET);

        return String.valueOf(hashids.decode(mixId)[0]);
    }
}
